package datastructure.tree;

/**
 * Given a BST T and a key K, search for the first entry larger than K
 * 
 * @author Lei
 */
public class SearchBSTForGreaterK
{

    public static TreeNode searchBSTForGreaterK(TreeNode root, int K)
    {
        TreeNode result = null;
        while (root != null)
        {
            if (root.value > K)
            {
                result = root;
                root = root.left;
            }
            else
            {
                root = root.right;
            }
        }

        return result;
    }

    public static void main(String args[])
    {
    }
}
